import win32gui
import win32con

class WindowManager:
    def __init__(self):
        self.ark_windows = []  # 存储最多3个窗口信息
        self.target_class = "MainWnd class of ArkEngine"
    
    def refresh_windows(self):
        """刷新窗口列表"""
        self.ark_windows.clear()
        win32gui.EnumWindows(self._enum_window_callback, None)
        # 只保留最多3个窗口
        self.ark_windows = self.ark_windows[:3]
    
    def _enum_window_callback(self, hwnd, _):
        """枚举窗口回调"""
        if win32gui.IsWindowVisible(hwnd):
            class_name = win32gui.GetClassName(hwnd)
            if class_name == self.target_class:
                title = win32gui.GetWindowText(hwnd)
                self.ark_windows.append({
                    "title": title,
                    "hwnd": hwnd
                })
    
    def get_windows(self):
        """获取窗口列表"""
        return self.ark_windows

# 创建全局实例
window_manager = WindowManager() 